home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / five.zip / FIVE.PAS < prev    next >
Pascal/Delphi Source File  |  1987-03-14  |  45KB  |  1,242 lines

  1. Program Five_thousand;
  2.  
  3.     Const Max_players = 15;
  4.  
  5.     Type Strategy = (Human,Comp_1,Comp_2,Comp_3);
  6.          Scores = record
  7.                        Points:         real;
  8.                        Scratches:      real;
  9.                        Player_name:    string[20];
  10.                        Player_type:    strategy;
  11.                        On_board:       boolean;
  12.                     end;
  13.          Die = record
  14.                     Value:   integer;
  15.                     Pulled:  boolean;
  16.                     Saved:   boolean;
  17.                     Marked:  boolean;
  18.                  end;
  19.          Dice = array[1..6] of Die;
  20.  
  21.  
  22.     Var Winnings:            array[1..Max_players] of real;
  23.         Losses:              array[1..Max_players] of real;
  24.         Score:               array[0..Max_players] of Scores;
  25.         Last_player:         integer;
  26.         Current_player:      integer;
  27.         Next_player:         integer;
  28.         Needed:              real;
  29.         Last_players_score:  real;
  30.         Games_played:        integer;
  31.         Silent:              boolean;
  32.         Number_of_players:   integer;
  33.         Cup:                 Dice;
  34.         Humans_want_to_play: boolean;
  35.         Someone_over:        boolean;
  36.         Problems:            boolean;
  37.         Ch:                  char;
  38.         index:               integer;
  39.  
  40.     Procedure Randomize;
  41.  
  42.          Var Reg_set:  record
  43.                             Ax:        integer;
  44.                             Bx:        integer;
  45.                             Cx:        integer;
  46.                             Dx:        integer;
  47.                             Bp:        integer;
  48.                             Si:        integer;
  49.                             Di:        integer;
  50.                             Ds:        integer;
  51.                             Es:        integer;
  52.                             Flags:     integer;
  53.                          end;
  54.              I:    integer;
  55.              J:    integer;
  56.              K:    integer;
  57.  
  58.          begin
  59.          Reg_set.Ax:= $2C00;
  60.          MSDos(Reg_set);
  61.          J:= Reg_set.Cx;
  62.          I:= Reg_set.Dx;
  63.          MemW[Dseg:$0129]:= I;
  64.          MemW[Dseg:$012B]:= J;
  65.          For i:= 1 to J mod 250 do
  66.               k:= random(i);
  67.          end;
  68.  
  69.     Procedure Display_all_players;
  70.  
  71.          Var Player:    integer;
  72.  
  73.          begin
  74.          window(36,2,78,24);
  75.          clrscr;
  76.          gotoxy(1,1);
  77.          writeln;
  78.          writeln('        PLAYERS AND THEIR SCORES');
  79.          writeln;
  80.          writeln;
  81.          writeln('     Name                  Score  Scratches');
  82.          for Player:= 1 to Number_of_players do
  83.               begin
  84.               write(Player:2,': ',Score[Player].Player_name);
  85.               gotoxy(25,6 + Player);
  86.               writeln(Score[Player].Points:8:0,'    ',
  87.                       Score[Player].Scratches:5:0);
  88.               end;
  89.  
  90.          if Number_of_players < 14
  91.               then
  92.                  begin
  93.                  writeln;
  94.                  writeln;
  95.                  end
  96.               else
  97.                  if Number_of_players <=14
  98.                       then
  99.                          writeln;
  100.          if Number_of_players < 8
  101.               then
  102.                  gotoxy(1,17);
  103.  
  104.          writeln('The last player was: ',Score[Last_player].Player_name);
  105.          if Last_player <> 0
  106.              then
  107.                 begin
  108.                 write('Their score was: ');
  109.                 textcolor(black);
  110.                 textbackground(white);
  111.                 write(Last_players_score:8:0);
  112.                 textcolor(white);
  113.                 textbackground(black);
  114.                 end;
  115.          end;
  116.  
  117.     Procedure Border;
  118.  
  119.          Const Horiz =         #205;
  120.                Vert =          #186;
  121.                Top_left =      #201;
  122.                Top_right =     #187;
  123.                Bottom_left =   #200;
  124.                Bottom_right =  #188;
  125.                Top_center =    #209;
  126.                Bottom_center = #207;
  127.                Center =        #179;
  128.  
  129.          Var x_pos:     integer;
  130.              y_pos:     integer;
  131.  
  132.          begin
  133.          window(1,1,80,25);
  134.          clrscr;
  135.          For x_pos:= 1 to 79 do
  136.               write(Horiz);
  137.          gotoxy(1,25);
  138.          For x_pos:= 1 to 79 do
  139.               write(Horiz);
  140.          x_pos:= 1;
  141.          For y_pos:= 2 to 24 do
  142.               begin
  143.               gotoxy(x_pos,y_pos);
  144.               write(Vert);
  145.               end;
  146.          x_pos:= 79;
  147.          For y_pos:= 2 to 24 do
  148.               begin
  149.               gotoxy(x_pos,y_pos);
  150.               write(Vert);
  151.               end;
  152.          gotoxy(1,1);
  153.          write(Top_left);
  154.          gotoxy(79,1);
  155.          write(Top_right);
  156.          gotoxy(35,1);
  157.          write(Top_center);
  158.          gotoxy(1,25);
  159.          write(Bottom_left);
  160.          gotoxy(79,25);
  161.          write(Bottom_right);
  162.          gotoxy(35,25);
  163.          write(Bottom_center);
  164.          x_pos:= 35;
  165.          For y_pos:= 2 to 24 do
  166.               begin
  167.               gotoxy(x_pos,y_pos);
  168.               write(Center);
  169.               end;
  170.          end;
  171.  
  172.     Procedure Initialize_all;
  173.  
  174.          Var index:     integer;
  175.  
  176.          begin
  177.          Problems:= False;
  178.          Last_player:= 0;
  179.          Current_player:= 0;
  180.          Next_player:= 0;
  181.          Games_played:= 0;
  182.          Number_of_players:= 0;
  183.          Last_players_score:= 0.0;
  184.          Textcolor(white);
  185.          Textbackground(black);
  186.          For index:= 1 to Max_players do
  187.               begin
  188.               Winnings[index]:= 0.0;
  189.               Losses[index]:= 0.0;
  190.               with Score[index] do
  191.                    begin
  192.                    Points:= 0.0;
  193.                    Scratches:= 0;
  194.                    Player_name:='not yet assigne....d';
  195.                    Player_type:= Human;
  196.                    On_board:= False;
  197.                    end;
  198.               end;
  199.          with Score[0] do
  200.               begin
  201.               Points:= 0.0;
  202.               Scratches:= 0;
  203.               Player_name:= 'New Game';
  204.               Player_type:= Human;
  205.               On_board:= False;
  206.               end;
  207.          Border;
  208.          Display_all_players;
  209.          end;
  210.  
  211.     Procedure Show_dice(Var Cup: Dice);
  212.  
  213.          Var Top:            string[3];
  214.              Bottom:         string[3];
  215.              Middle:         string[3];
  216.              Die_number:     integer;
  217.              Top_line:       integer;
  218.              X_pos:          integer;
  219.              Line:           integer;
  220.  
  221.          begin
  222.          Top:= #218 + #196 +#191;
  223.          Bottom:= #192 + #196 + #217;
  224.          for line:= 11 to 13 do
  225.               begin
  226.               gotoxy(1,line);
  227.               clreol;
  228.               end;
  229.          for line:= 19 to 21 do
  230.               begin
  231.               gotoxy(1,line);
  232.               clreol;
  233.               end;
  234.          For Die_number:= 1 to 6 do
  235.               begin
  236.               If Cup[Die_number].Saved
  237.                   then
  238.                      Top_line:= 11
  239.                   else
  240.                      Top_line:= 19;
  241.               if Cup[Die_number].Pulled
  242.                    then
  243.                       begin
  244.                       Textcolor(black);
  245.                       Textbackground(white);
  246.                       end;
  247.               x_pos:= 5 * (Die_number);
  248.               gotoxy(x_pos,Top_line);
  249.               write(Top);
  250.               gotoxy(x_pos,Top_line + 1);
  251.               write(#179,Cup[Die_number].Value:1,#179);
  252.               gotoxy(x_pos,Top_line + 2);
  253.               write(Bottom);
  254.               if Cup[Die_number].Pulled
  255.                    then
  256.                       begin
  257.                       Textcolor(white);
  258.                       Textbackground(black);
  259.                       end;
  260.               end;
  261.          end;
  262.  
  263.  
  264.     Procedure Turn_stats(Saved_points,Points_available:real);
  265.  
  266.  
  267.          begin
  268.          window(2,2,34,23);
  269.          clrscr;
  270.          writeln;
  271.          writeln('   Current Player Information');
  272.          writeln;
  273.          writeln('Player: ',Score[Current_player].Player_name);
  274.          writeln;
  275.          write('On the board? ');
  276.          if Score[Current_player].On_board
  277.               then
  278.                  writeln('YES')
  279.               else
  280.                  begin
  281.                  Textcolor(Black);
  282.                  Textbackground(White);
  283.                  writeln('NO');
  284.                  Textcolor(White);
  285.                  Textbackground(Black);
  286.                  end;
  287.          write('Points needed: ');
  288.          Needed:= Last_players_score + 50.0;
  289.          if Score[Current_player].On_board and (Needed <= 350.0)
  290.               then
  291.                  Needed:= 350.0;
  292.          if (not Score[Current_player].On_board) and (Needed <= 500.0)
  293.               then
  294.                  Needed:= 500.0;
  295.          writeln('          ',Needed:6:0);
  296.          writeln('The points available are: ',Points_available:5:0);
  297.          writeln;
  298.          writeln('Dice_saved:');
  299.          gotoxy(1,15);
  300.          writeln('Value of the dice saved:  ',Saved_points:5:0);
  301.          writeln;
  302.          writeln;
  303.          writeln('The dice on the table are:');
  304.          end;
  305.  
  306.     Procedure Test_cup;
  307.  
  308.           Var i:   integer;
  309.           begin
  310.           Randomize;
  311.           For i:= 1 to 6 do
  312.                begin
  313.                Cup[i].Saved:= False;
  314.                Cup[i].Marked:= False;
  315.                end;
  316.           Cup[1].Value:= 2;
  317.           Cup[2].Value:= 2;
  318.           Cup[3].Value:= 2;
  319.           Cup[4].Value:= 2;
  320.           Cup[5].Value:= 2;
  321.           Cup[6].Value:= 2;
  322.           end;
  323.  
  324.     Function Score_pulled(Var Cup:Dice):real;
  325.  
  326.          Var Points_this_pass:    real;
  327.              i:                   integer;
  328.              j:                   integer;
  329.              Count:               integer;
  330.              Talley:              array[1..6] of integer;
  331.              Ones:                integer;
  332.              Twos:                integer;
  333.              Threes:              integer;
  334.              Fours:               integer;
  335.              Fivers:               integer;
  336.              Sixes:               integer;
  337.  
  338.          Function Aces(Var Cup:Dice):real;
  339.  
  340.               Var i:    integer;
  341.                   Count:integer;
  342.  
  343.               begin
  344.               count:= 0;
  345.               For i:= 1 to 6 do
  346.                    if ((Cup[i].Value = 1) and Cup[i].Pulled) and
  347.                                               not (Cup[i].Marked)
  348.                         then
  349.                            begin
  350.                            Cup[i].Marked:= True;
  351.                            Count:= Count + 1;
  352.                            end;
  353.               Aces:= 100.0 * Count;
  354.               end;
  355.  
  356.          Function Fives(Var Cup:Dice):real;
  357.  
  358.               Var i:    integer;
  359.                   Count:integer;
  360.  
  361.               begin
  362.               count:= 0;
  363.               For i:= 1 to 6 do
  364.                    if ((Cup[i].Value = 5) and Cup[i].Pulled) and
  365.                                               not (Cup[i].Marked)
  366.                         then
  367.                            begin
  368.                            Cup[i].Marked:= True;
  369.                            Count:= Count + 1;
  370.                            end;
  371.               Fives:= 50.0 * Count;
  372.               end;
  373.  
  374.          Procedure Anomaly(Var Cup:Dice);
  375.  
  376.               Var Point:     real;
  377.                   Count:     integer;
  378.                   I:         integer;
  379.                   J:         integer;
  380.  
  381.               begin
  382.               for i:= 1 to 6 do
  383.                    Cup[I].Marked:= False;
  384.               i:= 1;
  385.               while Talley[I] <> 4 do
  386.                    I:= I + 1;
  387.               Point:= 100.0 * I;
  388.               if I = 1
  389.                    then
  390.                       Point:= 1000.0;
  391.               Count:= 0;
  392.               for J:= 1 to 6 do
  393.                    begin
  394.                    if (Cup[J].Value = I) and (Count < 3)
  395.                         then
  396.                            begin
  397.                            Cup[J].Marked:= True;
  398.                            Count:= Count + 1;
  399.                            end;
  400.                    end;
  401.               Point:= Point + Aces(Cup) + fives(Cup);
  402.               for I:= 1 to 6 do
  403.                    begin
  404.                    if not Cup[I].Marked
  405.                         then
  406.                            Count:= -1;
  407.                    Cup[I].Marked:= True;
  408.                    end;
  409.               if Count < 0
  410.                    then
  411.                       Point:= 0.0;
  412.               if Point > 500
  413.                    then
  414.                       Points_this_pass:= Point;
  415.  
  416.               end;
  417.  
  418.  
  419.          begin
  420.          Count:= 0;
  421.          Points_this_pass:= 0.0;
  422.          fillchar(Talley,Sizeof(Talley),0);
  423.          for i:= 1 to 6 do
  424.               if (not Cup[i].saved) and Cup[i].Pulled
  425.                    then
  426.                       begin
  427.                       Count:= Count + 1;
  428.                       Talley[Cup[i].Value]:= Talley[Cup[i].Value] + 1;
  429.                       Cup[i].Marked:= False;
  430.                       end;
  431.          if Count >0
  432.               then
  433.                  begin
  434.                  Ones:= 0;
  435.                  Twos:= 0;
  436.                  Threes:= 0;
  437.                  Fours:= 0;
  438.                  Fivers:= 0;
  439.                  Sixes:= 0;
  440.                  for i:= 1 to 6 do
  441.                       Case Talley[i] of
  442.                            1: Ones:= Ones + 1;
  443.                            2: Twos:= Twos + 1;
  444.                            3: Threes:= Threes + 1;
  445.                            4: Fours:= Fours + 1;
  446.                            5: Fivers:= Fivers + 1;
  447.                            6: Sixes:= Sixes + 1;
  448.                         end;
  449.                  if Ones = 6
  450.                       then
  451.                          begin
  452.                          Points_this_pass:= 1500;
  453.                          for i:= 1 to 6 do
  454.                               Cup[i].Marked:= true;
  455.                          end;
  456.                  if (Twos = 3) or ((Twos = 1) and (Fours = 1))
  457.                       then
  458.                          begin
  459.                          Points_this_pass:= 500;
  460.                          for i:= 1 to 6 do
  461.                               Cup[i].Marked:= True;
  462.                          end;
  463.                  if Sixes = 1
  464.                       then
  465.                          begin
  466.                          i:= 1;
  467.                          while Talley[i] <>6 do
  468.                          i:= i + 1;
  469.                          Points_this_pass:= 2 * 100.0 * i;
  470.                          if i = 1
  471.                               then
  472.                                  Points_this_pass:= 2000.0;
  473.                          for i:= 1 to 6 do
  474.                               if Cup[i].Pulled
  475.                                    then
  476.                                       Cup[i].Marked:= True;
  477.                          end;
  478.                  if Fours = 1
  479.                       then
  480.                          begin
  481.                          i:= 1;
  482.                          while Talley[i] <>4 do
  483.                               i:= i + 1;
  484.                          Count:= 0;
  485.                          for j:= 1 to 6 do
  486.                               if(Cup[J].Value = I) and (not Cup[J].Marked)
  487.                                    then
  488.                                       Count:= Count + 1;
  489.                          if Count >= 3
  490.                               then
  491.                                  begin
  492.                                  Points_this_pass:= 100.0 * i;
  493.                                  if i = 1
  494.                                       then
  495.                                          Points_this_pass:= 1000.0;
  496.                                  Count:= 0;
  497.                                  for j:= 1 to 6 do
  498.                                      begin
  499.                                      if (Cup[j].Value = i) and
  500.                                                (Count < 3) and
  501.                                                (Cup[j].Pulled) and
  502.                                                (not Cup[J].Marked)
  503.                                           then
  504.                                              begin
  505.                                              Cup[j].Marked:= True;
  506.                                              Count:= Count + 1;
  507.                                              end;
  508.                                      end;
  509.                               end;
  510.                          end;
  511.                  if (Twos = 1) and (Fours = 1)
  512.                       then
  513.                          anomaly(Cup);
  514.                  if Threes > 0
  515.                       then
  516.                          begin
  517.                          Threes:= Threes - 1;
  518.                          i:= 1;
  519.                          while Talley[i] <>3 do
  520.                          i:= i + 1;
  521.                          Points_this_pass:= 100.0 * i;
  522.                          If i = 1
  523.                               then
  524.                                  Points_this_pass:= 1000.0;
  525.                          for j:= 1 to 6 do
  526.                               if (Cup[j].Value = i) and Cup[j].Pulled
  527.                                    then
  528.                                       Cup[j].Marked:= True;
  529.                          end;
  530.                  if Threes = 1
  531.                       then
  532.                          begin
  533.                          i:= i + 1;
  534.                          while Talley[i] <>3 do
  535.                          i:= i + 1;
  536.                          Points_this_pass:= 100.0 * i + Points_this_pass;
  537.                          If i = 1
  538.                               then
  539.                                  Points_this_pass:= 1000.0 + Points_this_pass;
  540.                          for j:= 1 to 6 do
  541.                               if (Cup[j].Value = i) and Cup[j].Pulled
  542.                                    then
  543.                                       Cup[j].Marked:= True;
  544.                          end;
  545.  
  546.  
  547.                  if fivers = 1
  548.                       then
  549.                          begin
  550.                          i:= 1;
  551.                          while Talley[i] <>5 do
  552.                               i:= i + 1;
  553.                               Points_this_pass:= 100.0 * i;
  554.                               If i = 1
  555.                                    then
  556.                                       Points_this_pass:= 1000.0;
  557.                               Count:= 0;
  558.                               for j:= 1 to 6 do
  559.                                    if (Cup[j].Value = i) and (Count < 3) and
  560.                                                              (Cup[j].Pulled)
  561.                                              then
  562.                                                 begin
  563.                                                 Cup[j].Marked:= True;
  564.                                                 Count:= Count + 1;
  565.                                                 end;
  566.                          end;
  567.                  Points_this_pass:= Points_this_pass + Aces(Cup) + Fives(Cup);
  568.                  end;
  569.          for i:= 1 to 6 do
  570.               if (Cup[i].Pulled) and not Cup[i].Marked
  571.                    then
  572.                       Points_this_pass:= -1.0;
  573.          for i:= 1 to 6 do
  574.               Cup[i].Marked:= False;
  575.          Score_pulled:= Points_this_pass;
  576.          end;
  577.  
  578.     Function Score_unsaved(Var Cup:Dice):real;
  579.  
  580.          Var Points_this_pass:    real;
  581.              i:                   integer;
  582.              j:                   integer;
  583.              Count:               integer;
  584.              Talley:              array[1..6] of integer;
  585.              Ones:                integer;
  586.              Twos:                integer;
  587.              Threes:              integer;
  588.              Fours:               integer;
  589.              Fivers:               integer;
  590.              Sixes:               integer;
  591.  
  592.          Function Aces(Var Cup:Dice):real;
  593.  
  594.               Var i:    integer;
  595.                   Count:integer;
  596.  
  597.               begin
  598.               count:= 0;
  599.               For i:= 1 to 6 do
  600.                    if ((Cup[i].Value = 1) and not Cup[i].Saved) and
  601.                                               not (Cup[i].Marked)
  602.                         then
  603.                            begin
  604.                            Cup[i].Marked:= True;
  605.                            Count:= Count + 1;
  606.                            end;
  607.               Aces:= 100.0 * Count;
  608.               end;
  609.  
  610.          Function Fives(Var Cup:Dice):real;
  611.  
  612.               Var i:    integer;
  613.                   Count:integer;
  614.  
  615.               begin
  616.               count:= 0;
  617.               For i:= 1 to 6 do
  618.                    if ((Cup[i].Value = 5) and not Cup[i].Saved) and
  619.                                               not (Cup[i].Marked)
  620.                         then
  621.                            begin
  622.                            Cup[i].Marked:= True;
  623.                            Count:= Count + 1;
  624.                            end;
  625.               Fives:= 50.0 * Count;
  626.               end;
  627.  
  628.          Procedure Anomaly;
  629.  
  630.               begin
  631.               end;
  632.  
  633.  
  634.          begin
  635.          Count:= 0;
  636.          Points_this_pass:= 0.0;
  637.          fillchar(Talley,Sizeof(Talley),0);
  638.          for i:= 1 to 6 do
  639.               if not Cup[i].saved
  640.                    then
  641.                       begin
  642.                       Count:= Count + 1;
  643.                       Talley[Cup[i].Value]:= Talley[Cup[i].Value] + 1;
  644.                       Cup[i].Marked:= False;
  645.                       end;
  646.          if Count >0
  647.               then
  648.                  begin
  649.                  Ones:= 0;
  650.                  Twos:= 0;
  651.                  Threes:= 0;
  652.                  Fours:= 0;
  653.                  Fivers:= 0;
  654.                  Sixes:= 0;
  655.                  for i:= 1 to 6 do
  656.                       Case Talley[i] of
  657.                            1: Ones:= Ones + 1;
  658.                            2: Twos:= Twos + 1;
  659.                            3: Threes:= Threes + 1;
  660.                            4: Fours:= Fours + 1;
  661.                            5: Fivers:= Fivers + 1;
  662.                            6: Sixes:= Sixes + 1;
  663.                         end;
  664.                  if Ones = 6
  665.                       then
  666.                          begin
  667.                          Points_this_pass:= 1500;
  668.                          for i:= 1 to 6 do
  669.                               Cup[i].Marked:= true;
  670.                          end;
  671.                  if Twos = 3
  672.                       then
  673.                          begin
  674.                          Points_this_pass:= 500;
  675.                          for i:= 1 to 6 do
  676.                               Cup[i].Marked:= True;
  677.                          end;
  678.                  if Sixes = 1
  679.                       then
  680.                          begin
  681.                          i:= 1;
  682.                          while Talley[i] <>6 do
  683.                          i:= i + 1;
  684.                          Points_this_pass:= 2 * 100.0 * i;
  685.                          if i = 1
  686.                               then
  687.                                  Points_this_pass:= 2000.0;
  688.                          for i:= 1 to 6 do
  689.                               if not Cup[i].Saved
  690.                                    then
  691.                                       Cup[i].Marked:= True;
  692.                          end;
  693.                  if Fours = 1
  694.                       then
  695.                          begin
  696.                          i:= 1;
  697.                          while Talley[i] <>4 do
  698.                               i:= i + 1;
  699.                          Points_this_pass:= 100.0 * i;
  700.                          if i = 1
  701.                               then
  702.                                  Points_this_pass:= 1000.0;
  703.                          Count:= 0;
  704.                          for j:= 1 to 6 do
  705.                               begin
  706.                               if (Cup[j].Value = i) and (Count < 3) and
  707.                                                       (Cup[j].Pulled)
  708.                                         then
  709.                                            begin
  710.                                            Cup[j].Marked:= True;
  711.                                            Count:= Count + 1;
  712.                                            end;
  713.                               end;
  714.                          end;
  715.                  if (Twos = 3) and (Fours = 1)
  716.                       then
  717.                          anomaly;
  718.                  if Threes > 0
  719.                       then
  720.                          begin
  721.                          Threes:= Threes - 1;
  722.                          i:= 1;
  723.                          while Talley[i] <>3 do
  724.                          i:= i + 1;
  725.                          Points_this_pass:= 100.0 * i;
  726.                          If i = 1
  727.                               then
  728.                                  Points_this_pass:= 1000.0;
  729.                          for j:= 1 to 6 do
  730.                               if (Cup[j].Value = i) and Cup[j].Pulled
  731.                                    then
  732.                                       Cup[j].Marked:= True;
  733.                          end;
  734.                  if Threes = 1
  735.                       then
  736.                          begin
  737.                          i:= i + 1;
  738.                          while Talley[i] <>3 do
  739.                          i:= i + 1;
  740.                          Points_this_pass:= 100.0 * i + Points_this_pass;
  741.                          If i = 1
  742.                               then
  743.                                  Points_this_pass:= 1000.0 + Points_this_pass;
  744.                          for j:= 1 to 6 do
  745.                               if (Cup[j].Value = i) and Cup[j].Pulled
  746.                                    then
  747.                                       Cup[j].Marked:= True;
  748.                          end;
  749.  
  750.  
  751.                  if fivers = 1
  752.                       then
  753.                          begin
  754.                          i:= 1;
  755.                          while Talley[i] <>5 do
  756.                               i:= i + 1;
  757.                               Points_this_pass:= 100.0 * i;
  758.                               If i = 1
  759.                                    then
  760.                                       Points_this_pass:= 1000.0;
  761.                               Count:= 0;
  762.                               for j:= 1 to 6 do
  763.                                    if (Cup[j].Value = i) and (Count < 3) and
  764.                                                              (Cup[j].Pulled)
  765.                                              then
  766.                                                 begin
  767.                                                 Cup[j].Marked:= True;
  768.                                                 Count:= Count + 1;
  769.                                                 end;
  770.                          end;
  771.                  Points_this_pass:= Points_this_pass + Aces(Cup) + Fives(Cup);
  772.                  end;
  773.  
  774.          for i:= 1 to 6 do
  775.               Cup[i].Marked:= False;
  776.          Score_unsaved:= Points_this_pass;
  777.          end;
  778.  
  779.     Procedure Start_it_off;
  780.  
  781.          Var Player:    integer;
  782.              Name:      string[100];
  783.              Ok:        boolean;
  784.              Result:    integer;
  785.              Ch:        char;
  786.  
  787.          Procedure Instructions;
  788. {$I Instruct.pas }
  789.  
  790.          begin
  791.          Ok:= False;
  792.          Initialize_all;
  793.          window(2,2,34,24);
  794.          clrscr;
  795.          writeln;
  796.          writeln('              5,000');
  797.          writeln;
  798.          writeln('Welcome to a game of skill and');
  799.          write('Chance. The dice are HOT, so I''ll');
  800.          writeln('handle them for you. I also');
  801.          write('assume that you wish to play this');
  802.          writeln('game for money--the stakes are:');
  803.          writeln('a Quarter a game, and a Dime a');
  804.          writeln('scratch.');
  805.          writeln;
  806.          writeln;
  807.          write('Do you need an introduction? ');
  808.          read(kbd,Ch);
  809.          if upcase(Ch) = 'Y'
  810.               then
  811.                  Instructions;
  812.          repeat
  813.               gotoxy(1,13);
  814.               clreol;
  815.               write('How many players (1-15)?- ');
  816.               readln(Name);
  817.               Name:= copy(Name,1,2);
  818.               val(Name,Number_of_players,Result);
  819.          until (Number_of_players > 0) and
  820.                (Number_of_players < 16) and
  821.                (Result = 0);
  822.          writeln;
  823.          writeln('Now I need your names. If you');
  824.          writeln('want me to play, call me Comp1,');
  825.          writeln('Comp2, or Comp3.');
  826.          writeln;
  827.          for Player:= 1 to Number_of_players do
  828.               begin
  829.               Name:= '';
  830.               repeat
  831.                    gotoxy(1,19);
  832.                    clreol;
  833.                    write('Player No. ',Player:2,' ');
  834.                    readln(Name);
  835.                    if copy(Name,1,5) = 'Comp1'
  836.                         then
  837.                            Score[Player].Player_type:= Comp_1;
  838.                    if copy(Name,1,5) = 'Comp2'
  839.                         then
  840.                            Score[Player].Player_type:= Comp_2;
  841.  
  842.                    {if (Name = 'Comp3')
  843.                         then
  844.                            begin
  845.                            Ok:= False;
  846.                            gotoxy(1,19);
  847.                            write('I''m sorry, I have a headache');
  848.                            Delay(1500);
  849.                            Name:= '';
  850.                            end;}
  851.                    if copy(Name,1,5) = 'Comp3'
  852.                         then
  853.                            Score[Player].Player_type:= Comp_3;
  854.  
  855.                    Ok:= Name <> '';
  856.               until Ok;
  857.               Score[Player].Player_name:= copy(Name,1,20);
  858.               Display_all_players;
  859.               window(2,2,34,24);
  860.               end;
  861.          gotoxy(1,19);
  862.          clreol;
  863.          Current_player:= random(Number_of_players) + 1;
  864.          writeln('I''ve randomly chosen the first');
  865.          writeln('player:  ',Score[Current_player].Player_name);
  866.          writeln;
  867.          writeln('Good luck ladies and gentlemen!');
  868.          delay(2500);
  869.          end;
  870.  
  871.  
  872.     Procedure Play_a_hand(Player:integer);
  873.  
  874.          Var Pulled_score:        real;
  875.              Points_saved:        real;
  876.              Points_available:    real;
  877.              I:                   integer;
  878.              Count:               integer;
  879.              Scratch:             boolean;
  880.              Chicken:             boolean;
  881.              First_roll:          boolean;
  882.              Ch:                  char;
  883.  
  884. {$I Computer.Pas }
  885.  
  886.          Procedure Pull_dice(Var Cup:Dice);
  887.  
  888.               Const Pointer = '^';
  889.                     Pointer_loc: array[1..6] of integer = (6,11,16,21,26,31);
  890.                     Left = #075;
  891.                     Right = #077;
  892.                     Space = ' ';
  893.                     Rtn = #013;
  894.                     Esc = #027;
  895.                     Line = 22;
  896.  
  897.               Var x_pos:     integer;
  898.                   I:         integer;
  899.                   Ch:        char;
  900.                   All_done:  boolean;
  901.  
  902.               begin
  903.               I:= 0;
  904.               All_done:= False;
  905.               repeat
  906.                    I:= I + 1;
  907.               until (I = 6) or (not Cup[I].Saved);
  908.               gotoxy(1,Line);
  909.               clreol;
  910.               repeat
  911.                    x_pos:= Pointer_loc[I];
  912.                    gotoxy(x_pos,Line);
  913.                    write(Pointer);
  914.                    read(kbd,Ch);
  915.                    if (Ch = Esc) and keypressed
  916.                         then
  917.                            read(kbd,Ch);
  918.                    case upcase(Ch) of
  919.                         Left: begin
  920.                               gotoxy(x_pos,Line);
  921.                               write(' ');
  922.                               repeat
  923.                                    I:= I - 1;
  924.                                    if I < 1
  925.                                         then
  926.                                            I:= 6;
  927.                               until not Cup[I].Saved;
  928.                               x_pos:= Pointer_loc[I];
  929.                               gotoxy(x_pos,Line);
  930.                               write(' ');
  931.                               end;
  932.                        Right: begin
  933.                               gotoxy(x_pos,Line);
  934.                               write(' ');
  935.                               repeat
  936.                                    I:= I + 1;
  937.                                    if I > 6
  938.                                         then
  939.                                            I:= 1;
  940.                               until not Cup[i].Saved;
  941.                               x_pos:= Pointer_loc[I];
  942.                               gotoxy(x_pos,Line);
  943.                               write(' ');
  944.                               end;
  945.                          ' ': if Cup[I].Pulled
  946.                                    then
  947.                                       Cup[I].Pulled:= False
  948.                                    else
  949.                                       Cup[I].Pulled:= True;
  950.                          Rtn:All_done:= True;
  951.                       end;
  952.                    Show_dice(Cup);
  953.               until All_done;
  954.               gotoxy(1,line);
  955.               clreol;
  956.               end;
  957.  
  958.  
  959.          begin
  960.          Points_saved:= 0.0;
  961.          Points_available:= 0.0;
  962.          Scratch:= False;
  963.          First_roll:= True;
  964.          Problems:= False;
  965.          Chicken:= False;
  966.          Ch:= 'N';
  967.          for I:= 1 to 6 do
  968.               begin
  969.               Cup[I].Pulled:= False;
  970.               Cup[I].Saved:= False;
  971.               end;
  972.          Turn_stats(Points_saved,Points_available);
  973.          Show_dice(Cup);
  974.          repeat
  975.               if (Points_available < Needed) and
  976.                       (Score[Current_player].Player_type = Human)
  977.                    then
  978.                       begin
  979.                       gotoxy(1,22);
  980.                       write('Press any key to roll dice');
  981.                       repeat
  982.                            I:= random(6) + 1;
  983.                       until keypressed;
  984.                       end;
  985.               gotoxy(1,22);
  986.               clreol;
  987.               for I:= 1 to 6 do
  988.                    if not Cup[I].Saved
  989.                         then
  990.                            Cup[I].Value:= random(6) + 1;
  991.               Show_dice(Cup);
  992.               Scratch:= (Score_unsaved(Cup) = 0.0);
  993.               if First_roll and Scratch
  994.                    then
  995.                       Score[Current_player].Scratches:=
  996.                            Score[Current_player].Scratches + 1;
  997.               First_roll:= False;
  998.               if not Scratch
  999.                    then
  1000.                       begin
  1001.                       repeat
  1002.                            if Score[Current_player].Player_type = Human
  1003.                                 then
  1004.                                    Pull_dice(Cup)
  1005.                                 else
  1006.                                    begin
  1007.                                    Chicken:= Computer_player(Cup);
  1008.                                    if Chicken
  1009.                                         then
  1010.                                            Ch:= 'Y'
  1011.                                         else
  1012.                                            Ch:= 'N';
  1013.                                    Show_dice(Cup);
  1014.                                    Delay(3000)
  1015.                                    end;
  1016.                            Pulled_score:= Score_pulled(Cup);
  1017.                            Problems:= False;
  1018.                            if Pulled_score < 0.0
  1019.                                 then
  1020.                                    begin
  1021.                                    gotoxy(1,22);
  1022.                                    write('All pulled dice do not SCORE',#007);
  1023.                                    delay(1500);
  1024.                                    Problems:= True;
  1025.                                    for I:= 1 to 6 do
  1026.                                         Cup[I].Pulled:= False;
  1027.                                    end;
  1028.                            if Pulled_score = 0.0
  1029.                                 then
  1030.                                    begin
  1031.                                    gotoxy(1,22);
  1032.                                    write('You must pull a Score!');
  1033.                                    delay(1500);
  1034.                                    Problems:= True;
  1035.                                    end;
  1036.                       until Pulled_score > 0.0;
  1037.                       Points_saved:= Points_saved + Pulled_score;
  1038.                       Points_available:= Points_available + Pulled_score;
  1039.                       for I:= 1 to 6 do
  1040.                            if Cup[I].Pulled
  1041.                                 then
  1042.                                    begin
  1043.                                    Cup[I].Saved:= True;
  1044.                                    Cup[I].Pulled:= False;
  1045.                                    end;
  1046.                       Turn_stats(Points_saved,Points_available);
  1047.                       Show_dice(Cup);
  1048.                       if Score[Current_player].Player_type = Human
  1049.                            then
  1050.                               if Points_available >= Needed
  1051.                                    then
  1052.                                       repeat
  1053.                                            gotoxy(1,22);
  1054.                                            clreol;
  1055.                                            write('Quit while you''re ahead? ');
  1056.                                            read(kbd,Ch);
  1057.                                       until (upcase(Ch) = 'Y') or
  1058.                                                      (upcase(Ch) = 'N');
  1059.                       Chicken:= (upcase(Ch) = 'Y');
  1060.                       end;
  1061.               Count:= 0;
  1062.               for I:= 1 to 6 do
  1063.                    if Cup[I].Saved
  1064.                         then
  1065.                            Count:= Count + 1;
  1066.               if Count = 6
  1067.                    then
  1068.                       begin
  1069.                       Points_saved:= 0.0;
  1070.                       for I:= 1 to 6 do
  1071.                            Cup[I].Saved:= false;
  1072.                       end;
  1073.          until Scratch or Chicken;
  1074.          if Scratch
  1075.               then
  1076.                  begin
  1077.                  Last_players_score:= 0.0;
  1078.                  Score[Current_player].Scratches:=
  1079.                                        Score[Current_player].Scratches + 1;
  1080.                  gotoxy(10,22);
  1081.                  write('TOO BAD.. YOU SCRATCHED');
  1082.                  delay(1500);
  1083.                  end
  1084.               else
  1085.                  begin
  1086.                  if Points_available >= 500.0
  1087.                       then
  1088.                          Score[Current_player].On_board:= True;
  1089.                  Last_players_score:= Points_available;
  1090.                  Score[Current_player].Points:=
  1091.                       Score[Current_player].Points + Points_available;
  1092.                  if Score[Current_player].Points > Score[0].Points
  1093.                       then
  1094.                          Score[0].Points:= Score[Current_player].Points;
  1095.                  end;
  1096.          end;
  1097.  
  1098.     Procedure Play_a_game;
  1099.  
  1100.          Var Whose_over:          integer;
  1101.              Max_score:           real;
  1102.              Winner:              integer;
  1103.              Player:              integer;
  1104.  
  1105.          begin
  1106.          Someone_over:= False;
  1107.          repeat
  1108.               Play_a_hand(Current_player);
  1109.               if Score[Current_player].Points >= 5000.0
  1110.                    then
  1111.                       begin
  1112.                       Someone_over:= True;
  1113.                       Whose_over:= Current_player;
  1114.                       end
  1115.                    else
  1116.                       Last_player:= Current_player;
  1117.                       Current_player:= Current_player + 1;
  1118.                       if Current_player > Number_of_players
  1119.                            then
  1120.                               Current_player:= 1;
  1121.               Last_player:= Current_player - 1;
  1122.               if Last_player = 0
  1123.                    then
  1124.                       Last_Player:= Number_of_players;
  1125.               Display_all_players;
  1126.          until Someone_over;
  1127.          repeat
  1128.               Play_a_hand(Current_player);
  1129.               Last_player:= Current_player;
  1130.               Current_player:= Current_player + 1;
  1131.               if Current_player > Number_of_players
  1132.                    then
  1133.                       Current_player:= 1;
  1134.               Display_all_players;
  1135.          until Current_player = Whose_over;
  1136.          Max_score:= Last_players_score;
  1137.          for Player:= 1 to Number_of_players do
  1138.               if Score[Player].Points > Max_score
  1139.                    then
  1140.                       begin
  1141.                       Winner:= Player;
  1142.                       Max_score:= Score[Player].Points;
  1143.                       end;
  1144.          Current_player:= Winner;
  1145.          Last_player:= 0;
  1146.          Last_players_score:= 0.0;
  1147.          end;
  1148.  
  1149.     Procedure Show_winnings;
  1150.  
  1151.          Type Ending = (win,lose);
  1152.  
  1153.          Var Pay_off:        array[win..lose,1..Max_players] of real;
  1154.              Winner_gets:    real;
  1155.              Player:         integer;
  1156.              Played_to:      ending;
  1157.  
  1158.          begin
  1159.          Winner_gets:= 0.0;
  1160.          fillchar(Pay_off,sizeof(Pay_off),0);
  1161.          for Player:= 1 to Number_of_players do
  1162.               begin
  1163.               if Player <> Current_player
  1164.                    then
  1165.                       Played_to:= lose
  1166.                    else
  1167.                       Played_to:= win;
  1168.               Pay_off[Played_to,Player]:= 0.25 + 0.1 * Score[Player].Scratches;
  1169.               if Score[Player].Points = 0.0
  1170.                    then
  1171.                       Pay_off[Played_to,Player]:= Pay_off[Played_to,Player]*2;
  1172.               Winner_gets:= Winner_gets + Pay_off[Played_to,Player];
  1173.               end;
  1174.          Winner_gets:= Winner_gets - 0.25 -
  1175.                               0.1 * Score[Current_player].Scratches;
  1176.          Pay_off[win,Current_player]:= Winner_gets;
  1177.          for Player:= 1 to Number_of_players do
  1178.               begin
  1179.               Winnings[Player]:= Pay_off[win,Player] + Winnings[Player];
  1180.               Losses[Player]:= Pay_off[lose,Player] + Losses[Player];
  1181.               end;
  1182.          window(2,2,34,24);
  1183.          clrscr;
  1184.          writeln;
  1185.          writeln;
  1186.          writeln('Here''s the results of this game:');
  1187.          writeln;
  1188.          writeln(' Player               Wins  Loses');
  1189.          for Player:= 1 to Number_of_players do
  1190.               begin
  1191.               write(Player:2,' ',Score[Player].Player_name);
  1192.               gotoxy(23,Player  + 6);
  1193.               write('$',Pay_off[win,Player]:4:2,' $',Pay_off[lose,Player]:4:2);
  1194.               end;
  1195.          window(36,2,78,24);
  1196.          clrscr;
  1197.          gotoxy(1,1);
  1198.          writeln;
  1199.          writeln('      PLAYERS AND THEIR WINNINGS');
  1200.          writeln;
  1201.          writeln;
  1202.          writeln('     Name              Winnings  Losses');
  1203.          writeln;
  1204.          for Player:= 1 to Number_of_players do
  1205.               begin
  1206.               write(Player:2,': ',Score[Player].Player_name);
  1207.               gotoxy(25,6 + Player);
  1208.               writeln('$',Winnings[Player]:5:2,'   $',
  1209.                       Losses[Player]:5:2);
  1210.               end;
  1211.          write('The number of games Played = ',Games_played:4);
  1212.          end;
  1213.  
  1214.     begin
  1215.     Randomize;
  1216.     Start_it_off;
  1217.     Test_cup;
  1218.     Humans_want_to_play:= True;
  1219.     while Humans_want_to_play do
  1220.          begin
  1221.          Play_a_game;
  1222.          Games_played:= Games_played + 1;
  1223.          Show_winnings;
  1224.          repeat
  1225.               gotoxy(1,22);
  1226.               clreol;
  1227.               write('  Do you want to play again? ');
  1228.               read(kbd,Ch);
  1229.               Ch:= upcase(Ch);
  1230.          until (Ch = 'Y') or (Ch = 'N');
  1231.          if Ch = 'N'
  1232.               then
  1233.                  Humans_want_to_play:= False;
  1234.          for index:= 1 to Number_of_players do
  1235.               with Score[index] do
  1236.                    begin
  1237.                    Points:= 0.0;
  1238.                    Scratches:= 0;
  1239.                    On_board:= False;
  1240.                    end;
  1241.          end;
  1242.     end.